Get started: port example-0.c to GtkApplication
authorBastian Ilsø <bastianilso@src.gnome.org>
Wed, 28 Jan 2015 11:39:01 +0000 (11:39 +0000)
committerMatthias Clasen <mclasen@redhat.com>
Wed, 28 Jan 2015 21:31:12 +0000 (16:31 -0500)
https://bugzilla.gnome.org/show_bug.cgi?id=743638

examples/window-default.c

index 4b7a22f7856e017eddcf57eaade30cc69c04a4eb..3bb80f51051e4bbc9e0ff164b548dba2059362c2 100644 (file)
@@ -1,21 +1,28 @@
 #include <gtk/gtk.h>
 
-int
-main (int   argc,
-      char *argv[])
+static void
+activate (GtkApplication* app,
+          gpointer        user_data)
 {
   GtkWidget *window;
 
-  gtk_init (&argc, &argv);
-
-  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+  window = gtk_application_window_new (app);
   gtk_window_set_title (GTK_WINDOW (window), "Window");
+  gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);
+  gtk_widget_show_all (window);
+}
 
-  g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
-
-  gtk_widget_show (window);
+int
+main (int    argc,
+      char **argv)
+{
+  GtkApplication *app;
+  int status;
 
-  gtk_main ();
+  app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
+  g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
+  status = g_application_run (G_APPLICATION (app), argc, argv);
+  g_object_unref (app);
 
-  return 0;
+  return status;
 }